package com.clickpaas.materialsprocurement.service.Impl;

import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.CostCenterDTOResponse;
import com.clickpaas.materialsprocurement.dao.CostCenterDao;
import com.clickpaas.materialsprocurement.entity.CostCenterEntity;
import com.clickpaas.materialsprocurement.service.CostCenterService;
import com.clickpaas.materialsprocurement.utils.DataInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class CostCenterServiceImpl implements CostCenterService {
    @Resource
    private CostCenterDao costCenterDao;
    /**
     * 获取成本中心数据
     *
     * @param costCenterEntity
     * @return
     */
    @Override
    public List<CostCenterDTOResponse> getCostCenterInfo(CostCenterEntity costCenterEntity) {

        List<CostCenterDTOResponse> reDataList;
        try {
            /**
             * 入参为空,不查询
             */
            if (null == costCenterEntity || DataInfoUtil.isAllFieldNull(costCenterEntity)){
                return null;
            }else {
                reDataList = costCenterDao.queryCostCenterInfo(costCenterEntity);
            }
        } catch (Exception e) {
            log.info("入参对象异常,请检查：【{}】,报错信息：【{}】",costCenterEntity,e);
            return null;
        }
        if (null != reDataList && reDataList.size()>0){
            return reDataList;
        }
        return null;
    }

    /**
     * 成本中心转换为bean
     *
     * @param dataLists
     * @return
     */
    @Override
    public List<CostCenterEntity> costCenterDataConver(List<CostCenterDTOResponse> dataLists) {
        return DataInfoUtil.castListCopy(dataLists, CostCenterDTOResponse.class, CostCenterEntity.class);
    }
}
